import { feedApi } from '/api/feed'
import { isLogin } from '/store/mutations'
import { checkAuth } from '/store/actions'
import { GlobalData } from '/store/state'
import { $event } from '/utils'

Page({
  data: {
    navList: [],
  },
  onLoad: function(options) {
    this.getNavbarList()
    this.getPosition()
    $event.on('after:boot', this, () => {
      this.getPosition()
    })
  },
  getPosition() {
    this.setData({
      navigationHeight: GlobalData.navigationHeight,
    })
  },
  // 获取导航栏列表
  async getNavbarList() {
    const navbarList = await feedApi.getNavbarList()
    this.data.navList = navbarList.data
    this.setData({
      navList:this.data.navList,
    })
  },
  async jump(e: WechatMiniprogram.BaseEvent) {
    const item = e.currentTarget.dataset.item
    if (!isLogin()) {
      await checkAuth()
    }
    if (!item.show_link) {
      wx.showToast({
        title: '功能开发中',
        icon: 'none',
        duration: 1000,
      })
      return
    }
    if (item.type == 1){
      wx.navigateTo({
        url: item.show_link,
      })
    } else if (item.type == 2){
      wx.setStorageSync('pathUrl', item.show_link)
      wx.navigateTo({
        url: '/mine/customerService/customerService',
      })
    } else {
      wx.navigateToMiniProgram({
        appId: item.show_link,
        // path: 'pages/page2/page2?id=123',
        success(res) {
          console.info(res)
          // 打开成功
        }
      });
    }

  },
})
